﻿using Mall.Infrastructure.Container;
using Mall.Infrastructure.Model;
using Sx.Mall.Web.Filter;
using Sx.Mall.WebContract;
using Sx.Mall.WebContract.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Sx.Mall.Web.Controllers
{
    public class AdminController : Controller
    {
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 登陆页
        /// </summary>
        /// <returns></returns>
        public ActionResult Login() 
        {
            return View();
        }

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult Login(LoginUser dto)
        {
            if (dto.UserName=="" || dto.UserName==null && dto.pwd=="" ||dto.pwd==null)
            {
                ViewBag.Result =false;
                ViewBag.ErrorMessages = "用户名和密码不能为空";
                return View(dto);
            }
            else
            {
                var result = LoginHelper.Login(dto);
                if (result.IsResult)
                {
                    return RedirectToAction("Index", "Admin");
                }
                else
                {
                    ViewBag.Result = result.IsResult;
                    ViewBag.ErrorMessages = result.Message;
                    return View(dto);
                }
            }
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <returns></returns>
        public ActionResult LogOut()
        {
            LoginHelper.LoginOut();
            return View();
        }


        /// <summary>
        /// 用户管理
        /// </summary>
        /// <returns></returns>
        public ActionResult ManagerUser()
        {
            return View();
        }

        /// <summary>
        /// 产品大分类管理
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductBigTypeManage()
        {
            return View();
        }

        /// <summary>
        /// 产品管理
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductManage()
        {
            return View();
        }

        /// <summary>
        /// 产品小分类管理
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductSmallTypeManage()
        {
            return View();
        }

    }
}
